// ExpenseResultParser.java（新工具类）
package yourapp.expense.util;

import yourapp.expense.entity.Expense;

import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ExpenseResultParser {

  // 把 ResultSet 转成 Expense 列表（适用于 ExpenseWithCategoryNames 视图查询结果）
  public static List<Expense> parseExpensesFromResultSet(ResultSet rs) {
    List<Expense> expenses = new ArrayList<>();
    try {
      while (rs.next()) {
        Expense expense = new Expense();
        expense.setExpenseId(rs.getInt("expense_id"));
        expense.setAmount(rs.getBigDecimal("amount"));
        expense.setExpenseDate(rs.getDate("expense_date"));
        expense.setDescription(rs.getString("description"));
        expense.setPaymentAppName(rs.getString("payment_app_name"));
        expense.setShoppingAppName(rs.getString("shopping_app_name"));
        expense.setPurposeCategoryName(rs.getString("purpose_category_name"));
        expenses.add(expense);
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return expenses;
  }
}